package org.vaadin.nf4v.core.handler.impl;

import org.vaadin.nf4v.core.NavigableWindow;
import org.vaadin.nf4v.core.handler.WindowFactory;

/**
 * Default WindowFactory implementation.
 * Uses reflection to instantiate window. 
 */
public class DefaultWindowFactory implements WindowFactory {

    @Override
    public <T extends NavigableWindow> T createWindow(Class<T> windowClass, String contextName) {
        try {
            return windowClass.newInstance();
        } catch (Exception e) {
            throw new RuntimeException("Problem while instantiating window of class " + windowClass + ". Window should have no-arg constructor", e);
        }
    }
}
